<script setup>
import { ref, onMounted } from 'vue'
import { Edit, Delete } from '@element-plus/icons-vue'
import ChannelEdit from './components/ChannelEdit.vue'
import { artGetchannelsService } from '@/api/article'
import { artDelChannelService } from '@/api/article'
import { ElMessage } from 'element-plus'

const channelList = ref([])
const getChannelList = async () => {
  isLoading.value = true
  const res = await artGetchannelsService()
  channelList.value = res.data.data
  // console.log(channelList.value)
  isLoading.value = false
}
onMounted(() => {
  getChannelList()
})
const isLoading = ref(false)
// const onDelChannel = (row) => {
//     console.log(row)
// }
const onEditChannel = (row) => {
  dialog.value.open(row)
}
const onAddChannel = () => {
  dialog.value.open({})
}
const onSuccess = () => {
  getChannelList()
}
const dialog = ref()
const onDelChannel = async (row) => {
  //确认删除
  // await ElMessageBox.confirm('')
  await ElMessageBox.confirm('此操作将永久删除该文件, 是否继续?', '提示', {
    confirmButtonText: '确定',
    cancelButtonText: '取消',
    type: 'warning',
  })
  await artDelChannelService(row.id)
  //删除成功
  ElMessage.success('删除成功')
  getChannelList()
}
</script>
<template>
  <page-container title="文章分类">
    <template #extra>
      <el-button type="primary" @click="onAddChannel">测试按钮</el-button>
    </template>

    <el-table :data="channelList" style="width: 100%" v-loading="isLoading">
      <el-table-column label="序号" width="100" type="index"> </el-table-column>
      <el-table-column label="分类名称" prop="cate_name"></el-table-column>
      <el-table-column label="分类别名" prop="cate_alias"></el-table-column>
      <el-table-column label="操作" width="100">
        <template #default="{ row }">
          <el-button
            :icon="Edit"
            circle
            plain
            type="primary"
            @click="onEditChannel(row)"
          ></el-button>
          <el-button
            :icon="Delete"
            circle
            plain
            type="danger"
            @click="onDelChannel(row)"
          ></el-button>
        </template>
      </el-table-column>
      <template #empty
        >``
        <el-empty description="没有数据" />
      </template>
    </el-table>
    <ChannelEdit ref="dialog" @success="onSuccess"></ChannelEdit>
  </page-container>
</template>

<style lang="scss" scoped></style>
